package com.qiangesoft.bootcodegen.controller;

import com.qiangesoft.bootcodegen.framework.log.Log;
import com.qiangesoft.bootcodegen.pojo.dto.BcgTableImportDTO;
import com.qiangesoft.bootcodegen.pojo.dto.BcgTableDTO;
import com.qiangesoft.bootcodegen.pojo.query.BcgTableQuery;
import com.qiangesoft.bootcodegen.pojo.query.PageQuery;
import com.qiangesoft.bootcodegen.pojo.vo.BcgTableDetailVO;
import com.qiangesoft.bootcodegen.pojo.vo.BcgTableVO;
import com.qiangesoft.bootcodegen.pojo.vo.PageResultVO;
import com.qiangesoft.bootcodegen.service.IBcgTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 表配置 前端控制器
 * </p>
 *
 * @author qiangesoft
 * @date 2024-03-28
 */
@Api(tags = "数据库表配置")
@RequiredArgsConstructor
@RestController
@RequestMapping("/table")
public class BcgTableController {

    private final IBcgTableService tableService;

    @Log(module = "数据库表配置", operationName = "导入表")
    @ApiOperation(value = "导入表")
    @PostMapping("/import")
    public void saveTable(@RequestBody @Validated BcgTableImportDTO tableImportDTO) {
        tableService.saveTable(tableImportDTO);
    }

    @Log(module = "数据库表配置", operationName = "删除表")
    @ApiOperation(value = "删除表")
    @DeleteMapping("/{ids}")
    public void removeTable(@PathVariable List<Long> ids) {
        tableService.removeTable(ids);
    }

    @Log(module = "数据库表配置", operationName = "修改表")
    @ApiOperation(value = "修改表")
    @PutMapping("/{id}")
    public void updateTable(@PathVariable Long id, @RequestBody @Validated BcgTableDTO tableDTO) {
        tableService.updateTable(id, tableDTO);
    }

    @Log(module = "数据库表配置", operationName = "查询表")
    @ApiOperation(value = "查询表")
    @GetMapping
    public PageResultVO<BcgTableVO> listTable(@Validated PageQuery pageQuery, BcgTableQuery tableQuery) {
        return tableService.listTable(pageQuery, tableQuery);
    }

    @Log(module = "数据库表配置", operationName = "查询表详情")
    @ApiOperation(value = "查询表详情")
    @GetMapping("/{id}")
    public BcgTableDetailVO getTable(@PathVariable Long id) {
        return tableService.getTable(id);
    }

    @Log(module = "数据库表配置", operationName = "zip代码生成")
    @ApiOperation(value = "zip代码生成")
    @GetMapping("/codegenDownload/{id}")
    public void codegenDownload(@PathVariable Long id, HttpServletResponse response) {
        tableService.codegenDownload(id, response);
    }

    @Log(module = "数据库表配置", operationName = "本地代码生成")
    @ApiOperation(value = "本地代码生成")
    @GetMapping("/codegenLocal/{id}")
    public void codegenLocal(@PathVariable Long id) {
        tableService.codegenLocal(id);
    }

}
